function addcomment1(artid, commentatorid) {
    var text = $("#comment1content").val()
    if (text != '') {
        $.ajax({
            type: 'post',
            url: '/comment/addcomment1',
            contentType: "application/json",
            data: JSON.stringify({
                artid: artid,
                commentatorid: commentatorid,
                content: text
            }),
            success: function (rescode) {
                swal("ok", "success")
            },
            error: function () {
                swal("修改失败", "error")
            }
        });
        $("#comment1content").val('')
    }
}

function reply2model(artid, commentatorid, comment1id) {
    if ($("#reply2model" + comment1id).html() == '')
        $("#reply2model" + comment1id).html('  <div class="collapse" id="collapse' + comment1id + '">\n' +
            '                    <textarea id="comment2_' + comment1id + '" maxlength="150" placeholder="回复长度小于150"></textarea>\n' +
            '                    <div>\n' +
            '                        <input type="button" value="发送" onclick="addcomment2(' + artid + ',' + commentatorid + ',' + comment1id + ')">\n' +
            '                    </div>\n' +
            '                </div>');
    $('#collapse' + comment1id).collapse('toggle');
}

function addcomment2(artid, commentatorid, comment1id) {
    var text = $("#comment2_" + comment1id).val()
    if (text != '') {
        $.ajax({
            type: 'post',
            url: '/comment/addcomment2',
            contentType: "application/json",
            data: JSON.stringify({
                artid: artid,
                commentatorid: commentatorid,
                comment1id: comment1id,
                content: text
            }),
            success: function (rescode) {
                reply2model(artid, commentatorid, comment1id)
            },
            error: function () {
                swal("修改失败", "error")
            }
        });
    }
}

function comment2label(artid, commentatorid, comment1id) {
    var ht = $("#comment2label" + comment1id).val();
    if (ht == '') {
        $.ajax({
            type: 'get',
            url: '/comment/getcomment2_3/' + artid + '/' + comment1id,
            contentType: "application/json",
            success: function (rescode) {
                var html = ''
                for (var i = 0; i < rescode.length; i++) {
                    html += ' <div class="comment2" style="padding: 10px">\n' +
                        '                    <b class="comment2user">' + rescode[i]["commentatorname"] + '</b>：\n' +
                        '                    <span>' + rescode[i]["content"] + '</span>\n' +
                        '                    <div class="comment2func">\n' +
                        '                        <span>' + rescode[i]["createdate"] + '</span>\n' +
                        '                        <a onclick="commentsupport(' + rescode[i]["currid"] + ')"><span class="glyphicon glyphicon-thumbs-up" id="commentsupport' + rescode[i]["currid"] + '">' + rescode[i]["support"] + '</span></a>\n' +
                        '                        <a onclick="reply3model(' + artid + ',' + commentatorid + ',' + comment1id + ',' + rescode[i]["currid"] + ')" style="margin-right: 15px"><span>回复</span></a>\n' +
                        '                    </div>\n' +
                        '                    <div id="reply3model' + comment1id + '_' + rescode[i]["currid"] + '"></div>\n' +
                        '                </div>'
                }
                $("#comment2label" + comment1id).html(html);
            },
            error: function () {
                swal("修改失败", "error")
            }
        });
    }
    $('#comment2label' + comment1id).collapse('toggle');
}

alert(new Date().Format("yyyy-MM-dd HH:mm:ss"))
function reply3model(artid, commentatorid, comment1id, comment2id) {
    var currid = comment1id + "_" + comment2id;
    if ($("#reply3model" + currid).html() == '')
        $("#reply3model" + currid).html('    <div class="collapse" id="collapse' + currid + '">\n' +
            '                    <textarea id="comment2_' + currid + '" maxlength="150" placeholder="回复长度小于150"></textarea>\n' +
            '                    <div>\n' +
            '                        <input type="button" value="发送" onclick="addcomment3(' + artid + ',' + commentatorid + ',' + comment1id + ',' + comment2id + ')">\n' +
            '                    </div>\n' +
            '                </div>');
    $('#collapse' + currid).collapse('toggle');
}

function addcomment3(artid, commentatorid, comment1id, comment2id) {
    var text = $("#comment2_" + comment1id + "_" + comment2id).val()
    if (text != '') {
        $.ajax({
            type: 'post',
            url: '/comment/addcomment3',
            contentType: "application/json",
            data: JSON.stringify({
                artid: artid,
                commentatorid: commentatorid,
                comment1id: comment1id,
                comment2id: comment2id,
                content: text
            }),
            success: function (rescode) {
                reply3model(artid, commentatorid, comment1id, comment2id)
            },
            error: function () {
                swal("修改失败", "error")
            }
        });
    }
}

var map = new Map();

function commentsupport(commentid) {
    var value = Number($("#commentsupport" + commentid).html());
    if (map.has(commentid)) {
        map.delete(commentid)
        value--;
    } else {
        map.set(commentid, value);
        value++;
    }
    $("#commentsupport" + commentid).html(value)
    $.ajax({
        type: 'post',
        url: '/comment/updatesupport',
        contentType: "application/json",
        data: JSON.stringify({
            commentid: commentid,
            value: value
        })
    });
}
